package com.phcx.corporate.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/*
 * @Author: zmh
 * @Date: 2023/07/03/10:47
 * @Description: 获取企业码的鉴权逻辑
 */
@Slf4j

public class CodeAuthUtil {

    // 根据 统一代码 与 管理员所属登记机关代码 鉴权
    public static boolean getCodeAuthByLicence13(String licence13, String adminLicence42Code){
        return adminLicence42Code.equals("411300") || adminLicence42Code.equals(licence13.substring(2,8));
    }

    // 根据 管理员所属登记机关代码、名称 与 企业所属登记机关代码、名称 鉴权
    public static boolean getCodeAuthByInterface(String adminLicence42Code, String adminLicence42,
                                                 String corporateLicence42Code, String corporateLicence42){

        String[] regArray = {"411302","411392","411303","411393","411395","411366","411396"};
        boolean flag = Arrays.asList(regArray).contains(adminLicence42Code);

        if (flag) {
            if (adminLicence42Code.equals("411392")){
                flag = corporateLicence42.contains("油田分局") && corporateLicence42.contains("南阳");
                return corporateLicence42.contains(adminLicence42.substring(10, 14))
                        || corporateLicence42Code.startsWith(adminLicence42Code)
                        || flag;
            }
            return (corporateLicence42.contains(adminLicence42.substring(10, 14)) && corporateLicence42.contains("南阳"))
                    || corporateLicence42Code.startsWith(adminLicence42Code) ;
        }else {
            return corporateLicence42.contains(adminLicence42.substring(0, 2))
                    || corporateLicence42Code.startsWith(adminLicence42Code);
        }
    }

}
